<template>
  <Banner />
  <div class="section">
    <h2 class="section-title">搬家 为您推荐</h2>
    <el-row :gutter="24">
      <el-col :xs="24" :sm="12" :md="8" v-for="service in teamList" :key="service.id">
        <ServiceCard :service="service" />
      </el-col>
    </el-row>
  </div>

  <div class="section">
    <h2 class="section-title">热门评论</h2>
    <el-row :gutter="24">
      <el-col :xs="24" :sm="12" v-for="review in commentList" :key="review.id">
        <ReviewCard :review="review" />
      </el-col>
    </el-row>
  </div>
</template>

<script setup>

import ServiceCard from "@/components/ServiceCard.vue";
import ReviewCard from "@/components/ReviewCard.vue";
import {onMounted, reactive, ref} from "vue";
import {get} from "@/net/index.js";
import {ElMessage} from "element-plus";
import Banner from "@/components/Banner.vue";

const keywords = ref("")
const total = ref()
const teamList = ref([])
const commentList = ref([])
const pagination = reactive({
  pageSize: 3,
  currentPage: 1,
  total: 0
})


const loadTeam = () => {

  get(`/api/team/getTeamList/${pagination.currentPage}?keywords=${keywords.value || ''}`,(res)=>{
    total.value = res.total
    teamList.value = res.list
  },(err)=>{
    ElMessage.warning("请求失败")
    console.log(err)
  })

}

const loadComment = () => {

  get(`/api/comment/getCommentList/${pagination.currentPage}?keywords=${keywords.value || ''}`,(res)=>{
    total.value = res.total
    commentList.value = res.list
    // console.log(teamList.value)
    console.log(res)
  },(err)=>{
    ElMessage.warning("请求失败")
    console.log(err)
  })

}
onMounted(() => {
  loadTeam();
  loadComment();
})
</script>

<style scoped>

.content-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.section {
  background-color: #fff;
  border-radius: var(--border-radius);
  padding: 30px;
  margin-bottom: 30px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

.section-title {
  font-size: 24px;
  color: var(--text-color);
  margin-bottom: 25px;
  position: relative;
  padding-left: 15px;
  font-weight: 600;
}

.section-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 20px;
  background-color: var(--primary-color);
}

.el-row {
  margin-bottom: -20px;

  &:last-child {
    margin-bottom: 0;
  }
}

.el-col {
  margin-bottom: 20px;
}

</style>